Component({
  mixins: [],
  data: {
    animation:'',
    current:0,
    shi:'',
		xu:'',
		// bg:{
		// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN010lVHAV20xZqkr96RR_!!4161056916.png',
		// 	width:680,
		// 	height:671
		// },

		// line:{
		// 	url:'https://img.alicdn.com/imgextra/i2/4161056916/O1CN01ubTwd620xZqcBPt57_!!4161056916.png'
		// },

		// bar:{
		// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN01zinMeD20xZqctD906_!!4161056916.png'
		// },

		// prizeBg:{
		// 	url:'https://img.alicdn.com/imgextra/i1/4161056916/O1CN019oag2E20xZqfpsta8_!!4161056916.png'
		// },

		// lingQu:{
		// 	url:'https://img.alicdn.com/imgextra/i3/4161056916/O1CN010ESrAw20xZqw1t32b_!!4161056916.png'
		// },

		// shiLingQu:{
		// 	url:'https://img.alicdn.com/imgextra/i2/4161056916/O1CN0179dX9v20xZqXuxi4O_!!4161056916.png'
		// },

		showAddress:false,
		prizeId:'',
		parDa:''
  },
  props: {},
  didMount() {

		this.$page.prizePage = this

    this.animation = my.createAnimation();

    this.animation.translate('0%','150%').step()

    this.setData({ 
      ...getApp().pifu.prizePage,
      animation: this.animation.export() 
    });
    
		this.prize(this.props.prize)
		
		console.info(this.data.shi)
		console.info(this.data.xu)

  },
  didUpdate() {},
  didUnmount() {},
  methods: {

		prize(o){
			let shi = [];
			let xu = [];
			o.map((v,i) => {
				if(v.giftType == 1){
					shi.push(v)
				}else{
					xu.push(v)
				}
			})

			this.setData({
				shi:shi,
				xu:xu
			})
		},

		openAddress(e){
			let idx = e.target.dataset.idx;

			// this.setData({
			// 	showAddress:true,
			// 	prizeId:this.data.shi[idx].id,
			// 	parDa:this.data.shi[idx]
			// })

			// my.tb.openDetail ({
			// 			itemId: this.data.shi[idx].bindNumIid,
			// 			success: (res) => {
			// 				// my.alert({ content: "success" });
			// 			},
			// 			fail: (res) => {
			// 				// my.alert({ content: "fail - " + res.error });
			// 			},
			// });

			my.tb.confirmCustomOrder({
				data:{
					'itemId':parseInt(this.data.shi[idx].bindNumIid),
					'quantity':1
				},
				success:function(e) {   },
				// fail:function(e) {  my.alert({  title: 'fail ',  content: JSON.stringify(e)  })  }  
			});

			console.info()
		},

		getAddress(e){
			// this.$page.gress()

			console.info()

			 	my.authorize({
					scopes: 'scope.addressList',
					success: (res) => {
						my.tb.chooseAddress({
							addAddress: "show",
							searchAddress: "show",
							locateAddress: "show"
						}, (res) => {
							my.alert({ content: "success - " + JSON.stringify(res) })

							console.info(res)

							getApp().cloud.application.httpRequest({
								'path' : '/api/c/prize/address', 
								'method':'POST',
								'headers':{ "Content-Type":"application/json"},
								'params':{},
								'body':{
												id:this.data.shi[e.target.dataset.index].id,
												phone:res.telNumber,
												receiverAddress:res.detailInfo,
												receiverArea: res.countyName,
												receiverCity: res.cityName,
												receiverProvince:res.provinceName
											},
								'exts':{}  }).then(res => {

								console.log("用户领取奖品地址=====>",res);

								//判断是否是正常状态
								if(res.code != 200){
									my.alert({
										content:res.msg
									}) 
								}else{
									console.info('填写地址===》',res)
								}
							})

						})
					},
				});


		},

    closeList(){
      
      this.animation.translate('0%','-150%').step()
      this.setData({ animation: this.animation.export() })

      setTimeout(() => {
        this.$page.setData({
          isScroll:false,
          isShowPrize:false
        })
      }, 400);
    },


    prizeQH(e){

      //console.log(e.currentTarget.dataset.id);

      this.setData({
        current:e.currentTarget.dataset.id
      })
    },

    onChange(e){
      this.setData({
        current:e.detail.current
      }) 
    }

  },
});
